//
//  JoPhotoViewController.m
//  RunningMan
//
//  Created by 姜勇利 on 16/5/19.
//  Copyright © 2016年 JohnnyB. All rights reserved.
//

#import "JoPhotoViewController.h"
#import "JoPhotoTableViewCell.h"

@interface JoPhotoViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *photoTableView;

@property (nonatomic, strong) NSArray *nameArr;

@property (nonatomic, strong) NSMutableArray *mArrPhoto;

@end

@implementation JoPhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"照片";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.63 green:0.40 blue:0.82 alpha:1.0];
    [self creatSubViews];
    [self handleData];
    
}

#pragma mark -
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

#pragma mark -
- (void)creatSubViews
{
    self.photoTableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:self.photoTableView];
    self.photoTableView.delegate = self;
    self.photoTableView.dataSource = self;
    self.photoTableView.rowHeight = 44;
    [self.photoTableView registerClass:[JoPhotoTableViewCell class] forCellReuseIdentifier:@"PhotoTabeViewCellPool"];
}

#pragma mark - 
- (void)handleData
{
    self.nameArr = @[@"ZRuT.jpeg", @"sy575.jpg", @"JBmQ3.jpeg", @"gp.jpg", @"uRR28.jpeg", @"CaESv.png", @"c1e2511.jpg", @"c684.jpg", @"W039.jpg", @"GsWnH.jpeg"];
    self.mArrPhoto = [NSMutableArray array];
    for (int i = 0; i < 10; i++) {
        UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:self.nameArr[i]]];
        [self.mArrPhoto addObject:image];
    }
    
}

#pragma mark -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 10;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIImageView *image = [self.mArrPhoto objectAtIndex:indexPath.section];
    if (image.image.size.width < self.view.frame.size.width) {
        return image.image.size.height + 10;
    }
    else{
        CGFloat height = self.view.frame.size.width / image.image.size.width * image.image.size.height;
        return height + 10;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
    UIImageView *imageLine = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"25"]];
    [backView addSubview:imageLine];
    imageLine.frame = CGRectMake(20, 0, 40, 40);
    UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 2.f - 20, 0, self.view.frame.size.width / 2.f, 40)];
    [backView addSubview:dateLabel];
    dateLabel.textAlignment = 2;
    dateLabel.textColor = [UIColor colorWithRed:0.53 green:0.80 blue:0.98 alpha:1.0];
// 获取日期
    NSDate *senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY/MM/dd"];
    NSString *locationString=[dateformatter stringFromDate:senddate];
    dateLabel.text = locationString;
    
    backView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
    return backView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JoPhotoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PhotoTabeViewCellPool"];
    cell.photoImage.image = ((UIImageView *)self.mArrPhoto[indexPath.section]).image ;
    return cell;
}

#pragma mark -
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
